package cn.thoughtworks.service.impl;

import cn.thoughtworks.model.Size;
import cn.thoughtworks.service.Verify;

/**
 * 验证无效的数字
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @create 2018-07-27-15:38
 */
public class InvalidNumber implements Verify {
    /**
     * 判断输入的字符串能否转化为数字
     * @param size 道路网格大小
     * @param command 输入命令
     * @return
     */
    public boolean verify(Size size, String command) {
        String[] strs = command.split(";");
        String regex = "^0|[1-9]\\d*$";

        for (int i = 0; i < strs.length; i++) {
            String[] str2 = strs[i].split(" ");
            for (int j = 0; j < str2.length; j++) {
                String[] str3 = str2[j].split(",");
                for (int k = 0; k < str3.length; k++) {
                    if (!str3[k].matches(regex))
                        return false;
                }

            }
        }

        return true;
    }



}
